package com.tianyu.jty.system.task;

import com.jswzc.jiuling.service.order.DlServiceI;
import com.tianyu.jty.system.entity.ScheduleJob;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务工作类 大连 每天执行
 * @author ty
 * @date 2015年1月13日
 */
@DisallowConcurrentExecution
@Component("DayDl")
public class DayDl implements Job {

    private DlServiceI dlService;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            ClassPathXmlApplicationContext contexts;
            contexts = new ClassPathXmlApplicationContext("classpath*:/applicationContext-dubbo.xml");
            contexts.start();
            dlService = (DlServiceI) contexts.getBean("dlService"); // 获取远程服务代理
            //失效过期90券
            dlService.detail90();
            System.out.println("dl失效过期90券"+dlService.detail90());
            //dl拉取每日统计
            dlService.showStatistics();
            System.out.println("dl拉取每日统计"+dlService.showStatistics());
            //发货超过15天的自动确认收货
            dlService.confirmReceipt();
            System.out.println("dl发货超过15天的自动确认收货"+dlService.confirmReceipt());

            ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
            System.out.println("任务名称 = [" + scheduleJob.getName() + "]" + " 在 " + dateFormat.format(new Date()) + " 时运行");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
